<%@ page contentType="text/html;charset=utf-8"%>
<%@page import="java.sql.*"%>
<%
   int no = Integer.parseInt(request.getParameter("no"));

   Class.forName("com.mysql.jdbc.Driver");

   String url = "jdbc:mysql://localhost:3306/mydb";
   String username = "root";
   String password = "6473";

   Connection conn = DriverManager.getConnection(url, username, password);
   String sql = "select * from namecard where id =?";
   PreparedStatement stmt = conn.prepareStatement(sql);
   stmt.setInt(1,no);

   ResultSet rs = stmt.executeQuery();

   String result = "[";
   boolean check = rs.next();
	while (check) {
		result += "{";
		result += "\"name\":\""+rs.getString("name")+"\",";
		result += "\"address\":\""+rs.getString("address")+"\",";
		result += "\"telephone\":\""+rs.getString("telephone")+"\",";
		result += "\"age\":\""+rs.getString("age")+"\",";
		result += "\"gender\":\""+rs.getString("gender")+"\",";
		result += "\"id\":\""+rs.getString("id")+"\"}";
		if(check = rs.next()){
			result+=",";
		}	
	}
	result+="]";
	System.out.println(result);
%>
<%=result %>
